package com.briup.app03.service.impl;

import com.briup.app03.bean.UserInfo;
import com.briup.app03.bean.UserInfoExample;
import com.briup.app03.dao.UserInfoMapper;
import com.briup.app03.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author pete
 * @version 1.0
 * @date 2020/12/15 20:56
 */
@Service

public class UserInfoIServiceImpl implements IUserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public List<UserInfo> query(String realname, String gender) {

        UserInfoExample example = new UserInfoExample();
        if (!StringUtils.isEmpty(realname)) {
            example.createCriteria().andRealnameLike("%" + realname + "%");
        }
        if (StringUtils.isEmpty(gender)){
            example.createCriteria().andGenderEqualTo(gender);
        }
        List<UserInfo> list = userInfoMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(UserInfo userInfo) {

    }

    @Override
    public void SaveOrUpdate(UserInfo userInfo){
        if(userInfo.getId()==null){
            userInfoMapper.insert(userInfo);
        }else {
            userInfoMapper.updateByPrimaryKey(userInfo);
        }
    }
    @Override
    public void deleteById(long id){
        userInfoMapper.deleteByPrimaryKey(id);
    }
}
